import requests
from bs4 import BeautifulSoup

loginUrl= "https://ispace.uic.edu.hk/login/index.php"

session = requests.Session()

html_get = session.get(loginUrl, verify=False)

soup = BeautifulSoup(html_get.text, 'html.parser').find("input",{'name': 'logintoken'})['value']
print(soup)

postdata = {
    'anchor': "",
    'logintoken': soup,
    'username': "username",
    'password': "password"
}

header = {
    'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0",
    'Referer': loginUrl
}

html_post = session.post(loginUrl, postdata, headers=header, verify=False)

print(html_post.url)

save=open("ispace.html","wb")
save.write(html_post.text.encode())
save.close()